#include "qqcelltitle.h"
#include "ui_qqcelltitle.h"

QQCellTitle::QQCellTitle(const QString &groupname,QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::QQCellTitle)
{
     this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    ui->setupUi(this);
    ui->lblGroupname->setText(groupname);
    setOnlineAndGroup();
    ui->lblcount->setText(QString("[%1/%2]").arg(0).arg(0));
    this->setAttribute(Qt::WA_Hover,true);//开启悬停事件
    this->installEventFilter(this);
    isOpen=false;
    ui->lblGroupname->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    ui->lblcount->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    ui->lblimage->setAttribute(Qt::WA_TransparentForMouseEvents, true);
}

QQCellTitle::~QQCellTitle()
{
    delete ui;
}

void QQCellTitle::setOnlineAndGroup(int onlineCount, int groupCount)
{
    ui->lblcount->setText(QString("[%1/%2]").arg(onlineCount).arg(groupCount));
}

bool QQCellTitle::eventFilter(QObject *watched, QEvent *event)
{
    if(event->type()==QEvent::HoverEnter){
        this->setStyleSheet("background-color:rgb(100,100,100)");

        return true;
    }
    else if(event->type()==QEvent::HoverLeave)
    {
        this->setStyleSheet("background-color:#F0F0F0");
        return true;
    }
    else if(event->type()==QEvent::MouseButtonPress)
    {
        isOpen=!isOpen;
        if(isOpen)
        {
            this->setStyleSheet("background-color:rgb(100,100,100)");
            ui->lblimage->setPixmap(QPixmap(":/common/aio_arrow_down.png"));
           emit sigCellStatusChanged(isOpen);
            return true;


        }
        else
        {
            this->setStyleSheet("background-color:rgb(100,100,100)");
            ui->lblimage->setPixmap(QPixmap(":/common/aio_arrow_right.png"));
             emit sigCellStatusChanged(isOpen);
            return true;

        }

    }

    return false;
}
